library(tidyverse)
## -- Attaching packages ----------------------------------------------------------- tidyverse 1.3.0 --
## √ ggplot2 3.2.1 √ purrr 0.3.3
## √ tibble 2.1.3 √ dplyr 0.8.4
## √ tidyr 1.0.2 √ stringr 1.4.0
## √ readr 1.3.1 √ forcats 0.5.0
## Warning: package 'forcats' was built under R version 3.6.3
## -- Conflicts -------------------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(ggplot2)
library(EBImage)
##
## Attaching package: 'EBImage'
## The following object is masked from 'package:purrr':
##
## transpose
source("../xjx_lib/change_images.R")
info <- read.csv("../data/train_set/label.csv")
img = change_image(1)[[1]][[2]]
display(img, method = 'raster')

img1 = img
img1 = 1-(1-img1)/20
display(img1, method = 'raster')

draw_ave = function(indices, char)
{
l = length(indices)
ave_img = change_image(1)[[1]][[2]][100:900,100:700,] * 0
for(i in 1:l){
img = change_image(indices[i])[[1]][[2]][100:900,100:700,]
ave_img = ave_img + (1-img)/l
}
ave_img = 1-ave_img
display(ave_img, method = 'raster')
title(char)
}
map(1:22, ~draw_ave(info$Index[info$emotion_idx==.x], with(info, emotion_cat %>% unique)[.x]))













